function curry(fn, ...args) {
  let len = fn.length
  // 用于收集参数
  let allArgs = [...args]
  let resFn = function (...rest) {
    allArgs = [...allArgs, ...rest]
    // console.log(allArgs);
    if (allArgs.length >= len) {
      return fn(...allArgs)
    } else {
      return resFn
    }
  }
  return resFn
}

function add(a, b, c, d) {
  console.log(a + b + c + d);
}
let afterAdd = curry(add, 4)
afterAdd = afterAdd(1)
afterAdd = afterAdd(2,3)
// afterAdd(4)
